package com.hmall.trade.listener;

import com.hmall.trade.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PayStatusListener {
    @Autowired
    private IOrderService orderService;

    @RabbitListener(bindings = @QueueBinding(exchange = @Exchange(name = "pay.direct"),
            value = @Queue(name = "trade.pay.success.queue"),
            key = "pay.success"))
    public void listenPaySuccess(Long orderId) {
        log.info("PayStatusListener接收到MQ投递的消息,内容是:{}", orderId);
        orderService.markOrderPaySuccess(orderId);
    }
}
